$( document ).ready(function() {
		Parse.$ = jQuery;
		Parse.initialize("lken7qlOOU6DnGkQddYiIIVTTGBVGt8cHsTh0mN6", "lVOSFDfYALex78xE7WdpLadiZl61hUe1VrbnLA73");

		if (Parse.User.current()) {
		  $("#us").text(Parse.User.current().get("username"));
		  $("#user-info").show();
		} else {
			var CheminComplet = document.location.href;
			var NomDuFichier    = CheminComplet.substring(CheminComplet.lastIndexOf( "/" )+1 );
			if(NomDuFichier == "index.html")
				$("#user-info").hide();
			else
				window.setTimeout("location=('index.html');",0);
		}
		
		$("#login").click(function(){
			
			if (Parse.User.current()) {
			  alert("Vous êtes déjà connecté");
			} else {
		
				var username = $("#login-username").val();
				var password = $("#login-password").val();
				Parse.User.logIn(username, password, {
					success: function(user) {
					//alert("Bien connecté");
					$("#us").text(Parse.User.current().get("username"));
					$("#user-info").show();
					$("#redirect").show();
					var account = Parse.User.current().get("account");
					
					  if (account === "admin")
					  {
							
							window.setTimeout("location=('pages/adminupmc.html');",0000);
						}
					  else if (account === "bde")
					  {
						window.setTimeout("location=('pages/bde.html');",0000);
					}
					  else if (account === "commercant")
					  {
						window.setTimeout("location=('pages/commerce.html');",0000);
					}
					  else{
						  alert("type de compte non reconnu");
					  }
					},

					error: function(user, error) {
					  alert("Identifiant et/ou mot de passe non reconnu");
					  //Parse.User.logOut();
					  //location.reload();
					}
			    });
			}
		});
		$(".log-out").click(function(){
			
			Parse.User.logOut();
			var CheminComplet = document.location.href;
			var NomDuFichier    = CheminComplet.substring(CheminComplet.lastIndexOf( "/" )+1 );
			if(NomDuFichier == "index.html")
				$("#user-info").hide();
			else
				window.setTimeout("location=('../index.html');",0);
			
		});
	});